const fs = require('fs');
const path = require('path');

function deleteFilesWithPattern(directory) {
  fs.readdir(directory, (err, files) => {
    if (err) {
      console.error(`Error reading directory ${directory}: ${err}`);
      return;
    }

    files.forEach(file => {
      const filePath = path.join(directory, file);

      fs.stat(filePath, (err, stats) => {
        if (err) {
          console.error(`Error stating file ${filePath}: ${err}`);
          return;
        }

        if (stats.isDirectory()) {
          deleteFilesWithPattern(filePath); // 递归处理子目录
        } else {
          if (file.includes('_1')) {
            fs.unlink(filePath, err => {
              if (err) {
                console.error(`Error deleting file ${filePath}: ${err}`);
              } else {
                console.log(`Deleted file: ${filePath}`);
              }
            });
          }
        }
      });
    });
  });
}

// 获取当前项目目录
const projectDir = process.cwd();

// 调用函数开始删除含有 "_1" 的文件
deleteFilesWithPattern(projectDir);
